package com.nlp.shop.web.validate;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;
/**
 * 
 * @author zyl
 *
 */
public abstract class AbstractValidator extends Validator  {

	/**
	 * 
	 * 中文字符占两个字符
	 *
	 * @param c
	 * @param field
	 * @param notBlank
	 * @param minLen
	 * @param maxLen
	 * @param errorKey
	 * @param errorMessage
	 */
	protected void validateString(Controller c, String field, boolean notBlank, int minLen, int maxLen, String errorKey, String errorMessage) {
		String value = c.getPara(field);
		if (value == null || value.length() < minLen || value.length() > maxLen) 
			addError(errorKey, errorMessage);
		else if(notBlank && "".equals(value.trim()))
			addError(errorKey, errorMessage);
	}
}
